package com.yanqu.road.server.manger.analyze;

import com.yanqu.road.logic.thread.ThreadTaskManger;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.logic.thread.AnalyzeTask;
import com.yanqu.road.utils.executor.GeneralTask;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class AnalyzeMgr extends TempMgr {

    private static ThreadTaskManger threadTaskManger;

    private static AtomicInteger taskId = new AtomicInteger(1);

    private static List<Integer> analyzeItemIdList;

    @Override
    public boolean reloadData() {
        if(null == threadTaskManger) {
            threadTaskManger = new ThreadTaskManger(1, "AnalyzeTaskManager");
        }
        taskId = new AtomicInteger(1);
        initAnalyzeItemIdList();
        return true;
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }

    private static void initAnalyzeItemIdList(){
        analyzeItemIdList = StringUtils.stringToIntegerList("110031,110032,110049,110050,110051,110052,110053,110054,110055,110056,110057,110058,110066," +
                "110067,110072,110073,110087,110088,101000,101001,101002,101003,101004,101006,101007,101008,101009,101010,101011,101012,101013,101014", ",");
    }

    public static void addUserTitleUpgrade(GamePlayer player, long time) {
        addTask(new AnalyzeTask(player, time));
    }

    private static void addTask(GeneralTask generalTask) {
        threadTaskManger.addTask(taskId.getAndIncrement(), generalTask);
    }

    public static List<Integer> getAnalyzeItemIdList() {
        return new ArrayList<>(analyzeItemIdList);
    }
}
